package queue;

import java.util.stream.IntStream;

public class Demo {
	public static void main(String[] args) {
		int num = 0;
		
		for (int i = 1; i < 200; i++) {
			num += i;
		}
		
		System.out.println(num);
	}
}

class ProduceConsumer {
	private volatile int i;
	private volatile boolean isProduce;
	private static final Object Lock = new Object();

	public void produce() {
		synchronized (Lock) {
			if (isProduce) {
				try {
					Lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} else {
				System.out.println(Thread.currentThread().getName() + "->" + ++i);
				isProduce = true;
				Lock.notifyAll();
			}
		}
	}

	public void consumer() {
		synchronized (Lock) {
			if (isProduce) {
				System.out.println(Thread.currentThread().getName() + "->" + i);
				isProduce = false;
				Lock.notifyAll();
			} else {
				try {
					Lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

	}
}